package com.github.szhittech.service.task.impl;

import com.github.szhittech.MainPlugin;
import com.github.szhittech.bean.ClifeMavenResolver;
import com.github.szhittech.util.Logc;

import org.gradle.api.NamedDomainObjectList;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ModuleVersionIdentifier;
import org.gradle.api.artifacts.maven.MavenResolver;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.artifacts.ImmutableModuleIdentifierFactory;
import org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication;
import org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry;
import org.gradle.api.internal.attributes.ImmutableAttributes;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.Upload;
import org.gradle.internal.Describables;

import java.io.IOException;

/**
 * https://github.com/xufangzhen/AarUploader/blob/master/upload/src/main/groovy/com/xfz/upload/AarUploadTask.groovy
 */

public class UploadTask extends Upload {

    private ImmutableAttributes compileScopeAttributes;
    private ImmutableAttributes runtimeScopeAttributes;
    private ImmutableModuleIdentifierFactory moduleIdentifierFactory;
    private ProjectPublicationRegistry publicationRegistry;

//    @TaskAction
//    public void uploadArchives() throws IOException {
//        Project proj = getProject();
//        Logc.e("======UploadTask==uploadArchives=>2:"+proj.getClass().getName());
//        //configureUploadArchivesTask();
//    }
//    private void uploads(){
//        String groupId = "com.github.szhittech";
//        String ArtifactId = "hetxxxsdk";
//        String version = "0.0.5-SNAPSHOT";
//        String mavenDeployer = "mavenDeployer";
//        Logc.e("==+++++========configureUploadArchivesTask===getArtifactId>>>>>>" +ArtifactId);
//        Logc.e("===+++++=========configureUploadArchivesTask===getGroupId>>>>>>" + groupId);
//        Logc.e("===+++++=========configureUploadArchivesTask===getVersion>>>>>>" + version);
//        ModuleVersionIdentifier publicationId = moduleIdentifierFactory.moduleWithVersion(groupId, ArtifactId, version);
//        publicationRegistry.registerPublication((ProjectInternal) getProject(),
//                new DefaultProjectPublication(Describables.withTypeAndName("Maven repository", mavenDeployer), publicationId, true));
//    }

    @Override
    protected void upload() {
        //Logc.e("======UploadTask==upload:"+getConfiguration());
//        NamedDomainObjectList<MavenResolver> maven = getRepositories().withType(MavenResolver.class);
//        MavenResolver mavenResolver = new ClifeMavenResolver();
//        maven.add(mavenResolver);





        super.upload();
    }

    @Override
    public FileCollection getArtifacts() {
        //Logc.e("======UploadTask==getArtifacts:"+getConfiguration());
        return super.getArtifacts();
    }
}
